<?php
require_once('inc/global.php');
require_once('inc/userdata.php');
	require_once('inc/loginauth.php');
	   if(isset($_REQUEST['email']))
                DoLogin($_REQUEST['email'],$_REQUEST['password']);
if (isset($_GET['p']))
$pid = $_GET['p'];
if (isset($_GET['q']))
$qq = $_GET['q'];
if ($_SESSION['UserId'])
$uid = $_SESSION['UserId'];
function cartadd ($qq, $uid, $pid)
{
	    $conn = getConnection();
        $conn->query("INSERT INTO `N02223133_db`.`shoppingcart` (`odid`, `created_at`, `qty`, `session_id`, `pd_id`) 
		VALUES (NULL, CURRENT_TIMESTAMP, ".$qq.", ".$uid.", ".$pid.")");
		$conn->close();
}
$poutput = Productsdisplay();
	include('inc/header.php')
?>
</header>
<body>
<?php
	include('inc/login.php')
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td>
<? 
	include('inc/nav.php')
?>
</td></tr><tr><td>
<div class="contentstuff">
<h2><span class="ui-icon-triangle-1-e"></span>Products</h2>
<?php
if ($_GET['p'] != NULL)
{
cartadd($qq, $uid, $pid);
echo "Product Added to Cart";
}
 while ($ps = $poutput->fetch_assoc()){ ?>
<table class="prod-disp">
<tr><td align="center"><img src="images/products/<?=$ps['product_pic']?>"></td></tr>
<tr><td style="text-align:center;">
<script type="text/javascript">
		$(document).ready(function() {
	$("#inline<?=$ps['id']?>").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});
});
</script>
<button id="inline<?=$ps['id']?>" href="#p<?=$ps['id']?>">More Info</button>
<div style="display:none"><div id="p<?=$ps['id']?>">
<h1><?=$ps['product_name']?></h1>
<table border="0">
  <tr>
    <td rowspan="2"><img src="images/products/<?=$ps['product_pic']?>" />
</td>
    <td colspan="2"><p><?=$ps['product_desc']?><br />
        <h3>Left in Stock:<span style="color:#000;"> <?=$ps['inventory']?></span></h3></p></td>
  </tr>
  <tr>
    <td><h3>$<?=$ps['price']?></h3></td>
    <td align="right"><form>
    <input type="hidden" name="p" value="<?=$ps['id']?>">
    Order Quantity: <input name="q" id="q" type="number"><div class="navigation backend" style="text-align:right;"><input type="submit"  onclick="location.href='products.php?q=$q&p=$p'" value="Order Now"></form></a></div></td>
  </tr>
</table>
</div></div>

</td></tr>
<tr><td width="90px" style="text-align:center;"><strong><span style="text-align:center"><?=$ps['product_name']?></span></strong></td></tr>
</table>
<? } ?>
</div>
<button onClick="location.href='cart.php';">View Cart</button>
</div>
</body>
</html>